package com.ziyucoding.springboot.labs.lab4.concurrentdemo.example.synccontainer;

import com.ziyucoding.springboot.labs.lab4.concurrentdemo.annoations.NotThreadSafe;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.Vector;


/**
 * Vector 示例2
 *
 * @author ziyucoding
 * @date 2022-10-26
 **/
@Slf4j
@NotThreadSafe
public class VectorExample2 {

    private static List<Integer> items = new Vector<>();

    public static void main(String[] args) throws InterruptedException {
        while (true) {
            for (int i = 0; i < 10; i++) {
                items.add(i);
            }

            Thread thread1 = new Thread() {
                public void run() {
                    for (int i = 0; i < items.size(); i++) {
                        items.remove(i);
                    }
                }
            };

            Thread thread2 = new Thread() {
                public void run() {
                    for (int i = 0; i < items.size(); i++) {
                        items.get(i);
                    }
                }
            };

            thread1.start();
            thread2.start();
        }
    }
}
